﻿using jader3rd.VsXmlSorter;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Xml;

namespace VsXmlSorter_UnitTests
{
	[TestClass]
	public class SortTest
	{
		[TestMethod]
		public void TestSort()
		{
			var ext = new VsXmlSorterPackage();
			var xml = @"<parent Color=""Blue"">
							<ball Id=""3"" name=""cat"">
								<data content=""content for cat"" />
							</ball>
							<rock Id=""1"" name=""lizard"">
								<data content=""content for lizard"" />
							</rock>
							<ball Id=""2"" name=""dog"">
								<data content=""content for dog"" />
							</ball>
						</parent>";
			var testDoc = new XmlDocument();
			testDoc.PreserveWhitespace = true;
			testDoc.LoadXml(xml);
			ext.Sort(testDoc);

			Assert.AreEqual(1, testDoc.ChildNodes.Count);
			Assert.AreEqual(1, testDoc.ChildNodes[0].Attributes.Count);
			Assert.AreEqual(7, testDoc.ChildNodes[0].ChildNodes.Count);
			Assert.AreEqual("ball", testDoc.ChildNodes[0].ChildNodes[1].Name);
			Assert.AreEqual("rock", testDoc.ChildNodes[0].ChildNodes[5].Name);
			Assert.AreEqual("2", testDoc.ChildNodes[0].ChildNodes[1].Attributes["Id"].Value);
			Assert.AreEqual("cat", testDoc.ChildNodes[0].ChildNodes[3].Attributes["name"].Value);
		}
	}
}
